package com.todo.sight.application.frontend.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.sight.application.frontend.service.CityInfoAggService;
import com.todo.sight.application.iface.frontend.CityFrontendIface;
import com.todo.sight.application.iface.frontend.request.QueryCityDetailParam;
import com.todo.sight.application.iface.frontend.request.QueryCityInfoByNameParam;
import com.todo.sight.application.iface.frontend.request.QueryCityInfoListParam;
import com.todo.sight.application.iface.frontend.response.CityDetailVO;
import com.todo.sight.application.iface.frontend.response.CityInfoVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2024/5/14 13:42
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/city")
@Tag(name = "城市信息前台接口", description = "城市信息前台接口")
public class CityFrontedController implements CityFrontendIface {

    @Resource
    private CityInfoAggService cityInfoAggService;

    @Override
    @Operation(summary = "查询城市列表")
    @PostMapping("/queryCityInfoList")
    public BizResponse<List<CityInfoVO>> queryCityInfoList(@RequestBody QueryCityInfoListParam param) {
        if (param == null){
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()){
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return cityInfoAggService.queryCityInfoList(param);
    }

    @Override
    @Operation(summary = "根据主键查询城市详情")
    @PostMapping("/queryCityDetail")
    public BizResponse<CityDetailVO> queryCityDetail(@RequestBody QueryCityDetailParam param) {
        if (param == null){
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()){
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return cityInfoAggService.queryCityDetail(param);
    }

    @Override
    @Operation(summary = "根据名称查询城市信息")
    @PostMapping("/queryCityInfoByName")
    public BizResponse<List<CityInfoVO>> queryCityInfoByName(@RequestBody QueryCityInfoByNameParam param) {
        if (param == null){
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()){
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return cityInfoAggService.queryCityInfoByName(param);
    }
}
